import Vue from 'vue';
import $ from "jquery";
import './layer/layer.css';
import layer from './layer/layer';
import shelter from './js/selector/shelter';

Vue.config.productionTip = false;
let shelterUi = new shelter();

let _confirmLayer = 0;
let windowHeight = $(window).height();
if (windowHeight > window.screen.height) {
    windowHeight = document.body.clientHeight;
}

let defOption = {
    type: 1,
    shade: false,
    maxmin: true,
    closeBtn: 1,
    zIndex: 2147483599,
    title: "爬虫可视化点选配置工具",
    offset: ["30px", "30px"],
    content: '<div id="__paApa_container"></div>',
    area: ["450px", windowHeight * 0.8 + "px"],
    cancel: function(index) {
        event.stopPropagation();
        if (_confirmLayer > 0) {
            layer.close(_confirmLayer);
        }
        _confirmLayer = layer.confirm(
            "关闭爬虫可视化点选配置工具？", {
                icon: 0,
                title: "信息",
                zIndex: 2147483615
            },
            function(_index) {
                event.stopPropagation();
                layer.closeAll();
                _confirmLayer = -1;
                layer.msg("再见!", {
                    zIndex: 2147483620,
                    time: 3000,
                    icon: 1
                });
            },
            function(_index) {
                event.stopPropagation();
                layer.close(_index);
                _confirmLayer = -1;
            }
        );
        return false;
    }
};

let layerId = layer.open(defOption);

$("#layuiex-layer" + layerId + " .layuiex-layer-max").bind("click", function() {
    $(this).hide();
}).hide();

$("#layuiex-layer" + layerId + " .layuiex-layer-min").bind("click",
    function() {
        $(this).next().show();
    }
);

new Vue({
    el: "#__paApa_container",
    components: {},
    data() {
        return {
            selectedEl: null
        };
    },
    mounted() {
        let that = this;
        shelterUi.beginSelect(that.onDomClick, null,
            function(selectedEl) {
                that.selectedEl = selectedEl;
            });
    },
    methods: {
        onDomClick() {
            console.log('点击');
        }
    }
});